//////////Change the directory before running the code
//////// Active vs passive
cd "D:\data&code"
///// Load voting dataset
use pseudo_dataset/voting, clear
keep if contest == 1
drop if passive == .

///// Average by (contest,type) pairs
mark fm if vote_num == 0
mark pm if vote_num == 0.25
mark ab if vote_num == 0.5
mark pd if vote_num == 0.75
mark fd if vote_num == 1

sort passive
by   passive : egen mean_fm = mean(fm)
by   passive : egen mean_pm = mean(pm)
by   passive : egen mean_ab = mean(ab)
by   passive : egen mean_pd = mean(pd)
by   passive : egen mean_fd = mean(fd)

by passive : keep if _n == 1
keep pf_no passive mean_fm mean_pm mean_ab mean_pd mean_fd

rename mean_* *
keep passive fm pm ab pd fd

gen group = ""
replace group = "active"  if passive == 0
replace group = "passive" if passive == 1
drop passive
order group

tempfile x
save `x', replace

//////// B3 vs non-B3

///// Load voting dataset
use pseudo_dataset/voting, clear
rename big3 b3
keep if contest == 1
keep if passive == 1

///// Average by (contest,type) pairs
mark fm if vote_num == 0
mark pm if vote_num == 0.25
mark ab if vote_num == 0.5
mark pd if vote_num == 0.75
mark fd if vote_num == 1

sort b3
by   b3 : egen mean_fm = mean(fm)
by   b3 : egen mean_pm = mean(pm)
by   b3 : egen mean_ab = mean(ab)
by   b3 : egen mean_pd = mean(pd)
by   b3 : egen mean_fd = mean(fd)

by b3 : keep if _n == 1
keep pf_no b3 mean_fm mean_pm mean_ab mean_pd mean_fd

rename mean_* *
keep b3 fm pm ab pd fd

gen group = ""
replace group = "b3"  if b3 == 1
replace group = "x3" if b3 == 0
drop b3
order group
sort group

tempfile y
save `y', replace

/////////// Combine the two
use `x', clear
append using `y'
